/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package models.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import models.entity.Marca;
import models.entity.Modelo;
import utilidades.DataBaseInstance;

/**
 *
 * @author Matias
 */
public class MarcaModeloDao {
     //***//
   
     //***//
     public List<Modelo> getModelo(){
        List<Modelo> listaModelo = new LinkedList<Modelo>();
        ResultSet result = null;
     try {

            String query = "select "
                            + " mo.ID_MODELO,"
                            + " mo.NOMBRE,"
                            + " ma.ID_MARCA,"
                            + " ma.DESCRIPCION "
                    + " from MODELO mo join MARCA ma on mo.ID_MARCA = ma.ID_MARCA;";
             Connection conn = DataBaseInstance.getInstanceConnection();
            Statement stmt = conn.createStatement();
            result = stmt.executeQuery(query);
            Modelo modelo;
            Marca marca;
            while (result.next()) {
                modelo=new Modelo();
                marca=new Marca();
                modelo.setNombre(result.getString("NOMBRE"));
                modelo.setId_modelo(result.getInt("ID_MODELO"));
                marca.setDescripcion(result.getString("DESCRIPCION"));
                marca.setId_marca(result.getInt("ID_MARCA"));
                modelo.setMarca(marca);
                listaModelo.add(modelo);
            }

            result.close();
            stmt.close();
           DataBaseInstance.closeConnection(conn);

        } catch (SQLException se) {
            System.out.println(se.toString());
            System.err.println("Se ha producido un error de BD.");
            System.err.println(se.getMessage());
        }
        return listaModelo;
    }

}
